// 导入path模块
const path = require('path');
// 导入把index.html托管到根目录的插件
const htmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js',
    },
    plugins: [
        new htmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html'),
            filename: 'index.html',
        }),
    ],
    module: {
        rules: [
            { test: /\.css$/, use: ['style-loader', 'css-loader'] }, // 匹配css文件打包的配置
            { test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] }, // 匹配less文件打包的配置
            { test: /\.scss$/, use: ['style-loader', 'css-loader', 'sass-loader'] }, // 匹配scss文件打包的配置
            {
                test: /\.jpg|png|gif|bmp$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        name: '[name]_[hash:8].[ext]',
                        limit: 1024 * 100,
                    },
                },
            }, // 匹配图片文件打包的配置
            { test: /\.vue$/, use: 'vue-loader' }, // 解析vue组件的第三方loader
            { test: /\.js$/, use: 'babel-loader', exclude: /node_modules/ },
        ],
    },
};
